package com.aolong.archives.core.sysmanage.dao.impl;

import java.util.HashMap;
import java.util.Map;

import com.aolong.archives.core.sysmanage.dao.IRoleUserDao;
import com.rock.platform.dao.BaseDao;

public class RoleUserDao extends BaseDao implements IRoleUserDao {

	public void removeUser(String roleId, String[] userIds) {
		
		String strSql = "delete TSM_RoleUser where roleId = :roleId and userId = :userId";
		
		Map<String, Object> params = new HashMap<String,Object>();
		for(String userId : userIds)
		{
			params.clear();
			params.put("roleId", roleId);
			params.put("userId", userId);
			this.execute(strSql, params);
		}
	}

	public void addUser(String roleId, String[] userIds) {
		
		String strSql = "insert into tsm_roleuser(roleUserId,roleId,userID) "
						+ " select NEWID(),:roleId,:userId " 
						+ " where not exists (select 0 from tsm_roleuser where roleId =:roleId and userid = :userId)";
		Map<String, Object> params = new HashMap<String,Object>();
		for(String userId : userIds)
		{
			params.clear();
			params.put("roleId", roleId);
			params.put("userId", userId);
			this.execute(strSql, params);
		}
	}
}
